﻿using AutoMapper;
using LaserAutoTest.Application.Models;
using LaserAutoTest.Entity;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace LaserAutoTest.Application
{
    public class UserService:IUserService
    {
        private SqlSugarClient _db;
        private IMapper _mapper;

        public UserService(SqlSugarClient db, IMapper mapper)
        {
            _db = db;
            _mapper = mapper;
        }

        public List<UserModel> GetUsers()
        {
            var users = _db.Queryable<User>().ToList();
            var result = _mapper.Map<List<User>,List<UserModel>>(users);
            return result;
        }

        public bool CanUserLogin(string jobNumber,string password)
        {
            //_db.ChangeDatabase("laserAutoTest");
            var user = _db.Queryable<User>()
                .Where(t=>t.JobNumber==jobNumber&&t.Password==password)
                .First();
            return user != null;
        }
    }
}
